#include "Read_Data.h"


void Read_Data(){
    
    
    // Get the length of Data from matrix.dat
    Data_length = 0;

    sprintf(filename, "./data/%d/matrix.dat", file_number);
    
    p = fopen(filename, "r");
    while ((c=fgetc(p)) != EOF){
        if(c == '\n') Data_length++;
        } 
    fclose(p);

    Data_length = Data_length - 1;

    if(myrank == 0) printf("\nnumber of Data: %d\n", Data_length);
    
    // Read col/row/value data from matrix.dat
    Data_I = (int*)malloc(Data_length*sizeof(int)); // col
    Data_J = (int*)malloc(Data_length*sizeof(int)); // row
    Data_A_Value = (double*)malloc(Data_length*sizeof(double));

    sprintf(filename, "./data/%d/matrix.dat", file_number);
    p = fopen(filename, "r");
    fscanf(p, "%d", &Matrix_size);
    if(myrank == 0) printf("\nrows of matrix: %d\n", Matrix_size);
    for(i = 0; i < Data_length; i++){
        fscanf(p, "(%d,%d) %lf", &Data_I[i], &Data_J[i], &Data_A_Value[i]);
        } 
    fclose(p);

    // Read data from rhs.dat
    sprintf(filename, "./data/%d/rhs.dat", file_number);
    p = fopen(filename, "r");
    fscanf(p, "%d", &Matrix_size);
    Data_b_Value = (double*)malloc(Matrix_size*sizeof(double));
    for(i = 0; i < Matrix_size; i++){
        fscanf(p, "%lf", &Data_b_Value[i]);
        } 
    fclose(p);
    }
